package factory

import (
	"errors"
	"fmt"
)

type IOrderFind interface {
	GetList()
	GetAccountManger() IAccountManager
}

type IAccountManager interface {
	GetAccount() string
	SetAccount(account string) error
}

type accountManager struct {
	account string
}

func (am *accountManager) GetAccount() string {
	return am.account
}

func (am *accountManager) SetAccount(acc string) error {
	am.account = acc
	return nil
}

type tamllOrderFind struct {
	am *accountManager
}

func (taml *tamllOrderFind) GetList() {
	fmt.Println("天猫查询订单列表")
}

func (taml *tamllOrderFind) GetAccountManger() IAccountManager {
	return taml.am
}

type DouyinOrderFind struct {
	am *accountManager
}

func (douyin *DouyinOrderFind) GetList() {
	fmt.Println("抖音查询订单列表")
}

func (douyin *DouyinOrderFind) GetAccountManger() IAccountManager {
	return douyin.am
}

type IOrderFindFactory interface {
	CreateOrderFind(accunt string) IOrderFind
}

type tamllOrderFindFactory struct {
}

func (t *tamllOrderFindFactory) CreateOrderFind(account string) IOrderFind {
	return &tamllOrderFind{
		&accountManager{account: account},
	}
}

type douyinOrderFindFactory struct {
}

func (t *douyinOrderFindFactory) CreateOrderFind(account string) IOrderFind {
	// 可能有很多逻辑
	return &DouyinOrderFind{
		&accountManager{account: account},
	}
}

func NewOrderFindFactory(platform string) (factory IOrderFindFactory, err error) {
	switch platform {
	case "tamll":
		return &tamllOrderFindFactory{}, nil
	case "douyin":
		return &douyinOrderFindFactory{}, nil
	}
	return nil, errors.New("未定义类型")
}
